package com.javastudy.google.guava.utilities;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.google.common.base.Ascii;
import com.google.common.base.Objects;
import com.javastudy.data.Book;
import com.javastudy.data.Person;
import com.google.common.base.MoreObjects;
import com.google.common.base.Ascii;
import com.google.common.base.CharMatcher;
import com.google.common.base.Converter;
import com.google.common.base.Charsets;
import com.google.common.base.Defaults;
import com.google.common.base.Enums;
import com.google.common.base.Equivalence;
import com.google.common.base.FinalizableReference;
import com.google.common.base.MoreObjects.ToStringHelper;

public class GuavaBaseUtilitiesTest {
    Person person;
    @Before
    public void before() throws Exception {
        person = new Person();
        person.setName("Name John");
        person.setAge(29);

        Book book = new Book();
        book.setName("老人与海");
        book.setPrice(26);
        person.setBook(book);
    }
    
	/**
	 * 注意：JDK7引入的Objects类提供了一样的方法Objects.equals。
	 */
	@Test
	public void testObjectsEqual() {
		short p = Defaults.defaultValue(short.class);
		Objects.equal("a", "a"); // returns true
		Objects.equal(null, "a"); // returns false
		Objects.equal("a", null); // returns false
		Objects.equal(null, null); // returns true

	}
	
	/**
	 * 注意：JDK7引入的Objects类提供了一样的方法Objects.hash(Object...)
	 */
	@Test
	public void testObjectsHashCode(){
		
	}
	
	/**
	 * 这个有点奇怪，不知道怎么用好。传进去的对象的属性没有打印出来
	 */
	@Test
	public void testMoreObjectsToString(){
		String val = MoreObjects.toStringHelper(person).add("age", person.getAge()).toString();
		System.out.println(val);
		
		// Returns "ClassName{x=1}"
		
//		Objects.toStringHelper(this).add("x", 1).toString();
		// Returns "MyObject{x=1}"
//		Objects.toStringHelper("MyObject").add("x", 1).toString();
	}

	@Test
	public void test() {

		fail("Not yet implemented");
	}

}
